/*******************************************************************************
 This MASTER do file is to replicate outcomes for the research paper 
 
	"Private But Misunderstood?: Evidence on Measuring Intimate Partner Violence 
	  via Self-Interviewing in Rural Liberia and Malawi"
	
 It does the following:
  0. set up working directory and install required Stata packages
  1. generate tables in the paper
 
 Related folder paths:
  - where figures exported: 	/output/
 
 2024.08.01 (David S. Park) Created
*******************************************************************************/
clear all
clear all
set maxvar 50000
set matsize 500

/*******************************************************************************
 0. Set up working directory and install required Stata packages
*******************************************************************************/
// root folder (REPLICATOR: change this to where the replication package folder is saved)
cap noisily cd "/Users/DSP/Dropbox/Research/Projects/GiveDirectly-USAID/analysis/ACASI effects/HarvardDataverse_replication"

// folder to export tables
global raw_folder "output"

// install Stata packages required to run replication
ssc install estout
ssc install distinct
*******************************************************************************/

	// Control variables in regressions
	local controls ///
		currently_partnered age hh_size ///
		ipv_years_educ ipv_eng_readorwrite mobile_phone ///
		index_foodsec total_expend_usd_mon wealth_b_total_usd nonagincome_usd ///
		own_incomesource num_child age_diff_spouse
			
	global controls_rm = ""

	foreach XXX in `controls' {
		global controls_rm ${controls_rm} `XXX'_m `XXX'_r
	}

/*******************************************************************************
 Table 1. Summary Statistics and Experimental Balance
*******************************************************************************/
local texname table1
local numcol 4
local numcol_plus1 = `numcol' + 1

	/******************** Stata program *********************/
	cap program drop balance_check
	program balance_check
		syntax, yvarlist(string)

		eststo : estpost su `yvarlist' if acasi_ipv_treat==0
		eststo : estpost ttest `yvarlist', by(acasi_ipv_treat_inverse) unequal
		
	end
	/********************************************************/
	
use "replicationData.dta", clear
gen acasi_ipv_treat_inverse = 1 - acasi_ipv_treat

// Panel A. Demographics 
local panel_text "Panel A. Demographics"
local yvarlist currently_partnered age hh_size 

est clear	
foreach SSS in gd_mw_endline gd_lrw2_endline {
	preserve
	keep if survey=="`SSS'"
	balance_check, yvarlist(`yvarlist')
	restore
}

lab var currently_partnered	"=1 if currently married or has partner"
lab var age					"Age"
lab var hh_size				"Number of household members"

#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) label number 
	starlevels(* 0.10 ** 0.05 *** 0.01)
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule")
	posthead(
		" & \multicolumn{2}{c}{Malawi} & \multicolumn{2}{c}{Liberia} \\ "
		"\cmidrule(lr){2-3} \cmidrule(lr){4-5}"
		" & \begin{tabular}{c} FTFI \\ Mean [SD] \end{tabular} & \begin{tabular}{c} SI \\ - FTFI \end{tabular} 
		  & \begin{tabular}{c} FTFI \\ Mean [SD] \end{tabular} & \begin{tabular}{c} SI \\ - FTFI \end{tabular}  \\"
		"\midrule"
		"\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\"
		) 
	cells(
		"mean(fmt(%9.2fc) pattern(1 0 1 0)) b(star fmt(%9.2fc) pattern(0 1 0 1))" 
		"sd(par([ ]) fmt(%9.2fc) drop(currently_partnered) pattern(1 0 1 0)) se(par fmt(%9.2fc) pattern(0 1 0 1))")  
	;
#d cr	

// Panel B. Education and mobile phone ownership
local panel_text "Panel B. Education and mobile phone ownership"
local yvarlist ipv_years_educ ipv_eng_readorwrite mobile_phone

est clear	
foreach SSS in gd_mw_endline gd_lrw2_endline {
	preserve
	keep if survey=="`SSS'"
	balance_check, yvarlist(`yvarlist')
	restore
}

lab var ipv_years_educ		"Years of education"
lab var ipv_eng_readorwrite	"=1 if able to write/read"
lab var mobile_phone		"=1 if has access to mobile phone"

#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label  
	starlevels(* 0.10 ** 0.05 *** 0.01)
	posthead(
		"\\"
		"\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\"
		) 
	cells(
		"mean(fmt(%9.2fc) pattern(1 0 1 0 1 0)) b(star fmt(%9.2fc) pattern(0 1 0 1 0 1))" 
		"sd(par([ ]) fmt(%9.2fc) drop(ipv_eng_readorwrite mobile_phone) pattern(1 0 1 0 1 0)) se(par fmt(%9.2fc) pattern(0 1 0 1 0 1))")  
	;
#d cr

// Panel C. Household wealth
local panel_text "Panel C. Household wealth"
local yvarlist index_foodsec total_expend_usd_mon wealth_b_total_usd nonagincome_usd 

est clear	
foreach SSS in gd_mw_endline gd_lrw2_endline {
	preserve
	keep if survey=="`SSS'"
	balance_check, yvarlist(`yvarlist')
	restore
}	

lab var index_foodsec			"Food security index (z-score)"
lab var total_expend_usd_mon	"Total expenditure (monthly)"
lab var wealth_b_total_usd		"Net value of durables, livestock, and financial asset"
lab var nonagincome_usd			"Non-agricultural income (monthly)"

#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label  
	starlevels(* 0.10 ** 0.05 *** 0.01)
	posthead(
		"\\"
		"\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\"
		) 
	cells(
		"mean(fmt(%9.2fc) pattern(1 0 1 0 1 0)) b(star fmt(%9.2fc) pattern(0 1 0 1 0 1))" 
		"sd(par([ ]) fmt(%9.2fc) pattern(1 0 1 0 1 0)) se(par fmt(%9.2fc) pattern(0 1 0 1 0 1))")  
	;
#d cr

// Panel D. Empowerment-related outcomes
local panel_text "Panel D. Empowerment-related outcomes"
local yvarlist own_incomesource	/* num_child */ age_diff_spouse

est clear	
foreach SSS in gd_mw_endline gd_lrw2_endline {
	preserve
	keep if survey=="`SSS'"
	balance_check, yvarlist(`yvarlist')
	restore
}
		
lab var own_incomesource 	"=1 if has her own income source"	
lab var num_child 			"Number of children"	
lab var age_diff_spouse 	"Age difference from spouse"	
	
#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label  
	starlevels(* 0.10 ** 0.05 *** 0.01) sub(" 0.00" "" " (0.00) " "" " [0.00]" "")
	posthead(
		"\\"
		"\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\"
		) 
	cells(
		"mean(fmt(%9.2fc) pattern(1 0 1 0)) b(star fmt(%9.2fc) pattern(0 1 0 1))" 
		"sd(par([ ]) fmt(%9.2fc) drop(own_incomesource) pattern(1 0 1 0)) se(par fmt(%9.2fc) pattern(0 1 0 1))")  
	;
#d cr

// Panel E. Treatment status in parent study
local panel_text "Panel E. Treatment status in parent study"
local yvarlist GD_treat MA_treat

est clear	
foreach SSS in gd_mw_endline gd_lrw2_endline {
	preserve
	keep if survey=="`SSS'"
	balance_check, yvarlist(`yvarlist')
	restore
}
		
lab var GD_treat 	"=1 if in cash transfers villages"	
lab var MA_treat 	"=1 if in market access treatment villages"
	
#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label  
	starlevels(* 0.10 ** 0.05 *** 0.01) sub(" 0.00" "" " (0.00) " "" " [0.00]" "")
	posthead(
		"\\"
		"\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\"
		) 
	cells(
		"mean(fmt(%9.2fc) pattern(1 0 1 0)) b(star fmt(%9.2fc) pattern(0 1 0 1))" 
		"sd(par([ ]) fmt(%9.2fc) drop(*) pattern(1 0 1 0)) se(par fmt(%9.2fc) pattern(0 1 0 1))")  
	;
#d cr

// Last line (with observations)	
foreach SSS in gd_mw_endline gd_lrw2_endline {
	preserve
	keep if survey=="`SSS'"
	su acasi_ipv_treat
	local `SSS'_obs `r(N)'	
	restore
}

estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	prefoot("\midrule" "Observations & \multicolumn{2}{c}{`:display %5.0fc `gd_mw_endline_obs''} & \multicolumn{2}{c}{`:display %5.0fc `gd_lrw2_endline_obs''}\\") ///
	postfoot("\bottomrule" "\end{tabular}")		
*******************************************************************************/


/*******************************************************************************
 Table 2. Self-interviewing (SI) Screening Questions
*******************************************************************************/
local texname table2

use "replicationData.dta", clear

drop if gd_lrw1 // no screening questions for gd_lrw1_endline
keep if !mi(acasi_ipv_treat) // keeping only ipv sample (excluding men, those with hearing/seeing problem, etc.)
	
// Questions for which answer should be YES
local yvarlist acasi_screening_q1 acasi_screening_q2 acasi_screening_q4 acasi_screening_q5 acasi_screening_q6

	// Imputing zeroes for DK/RF
	foreach yvar in `yvarlist' {
		replace `yvar' = 0 if mi(`yvar') & !mi(acasi_ipv_treat)
	}
	
est clear
eststo : estpost su `yvarlist' if gd_mw
eststo : estpost su `yvarlist' if gd_lrw2
	
lab var acasi_screening_q1 "1. Are you a woman?"
lab var acasi_screening_q2 "2. Do you live in [the county/district where the survey is being conducted]? "
lab var acasi_screening_q4 "3. In the past week, did you sleep, during day or night?"
lab var acasi_screening_q5 "4. In the past year, did it rain in your village one time or more?"
lab var acasi_screening_q6 "5. Have you heard about Coronavirus?"
	
#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) number label 
	prehead("\begin{tabular}{l *{2}{c}}" "\toprule")
	posthead(
		" & \multicolumn{2}{c}{Mean (=1 if yes)} \\ "
		"\cmidrule(lr){2-3}"
		" & \multicolumn{1}{c}{Malawi} & \multicolumn{1}{c}{Liberia} \\"
		"\midrule"
		"\textit{Questions for which answer should be yes:} \\"
		) 
	cells("mean(fmt(%9.2f))" ) 
	;
#d cr

// Yes to all five & No to int'l travel
local yvarlist acasi_screening_pass5 acasi_screening_pass3

lab var acasi_screening_pass5 "=1 if YES to all five questions" 
lab var acasi_screening_pass3 "=1 if YES to questions 1,2, and 5"
est clear
eststo : estpost su `yvarlist' if gd_mw
eststo : estpost su `yvarlist' if gd_lrw2

#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label 
	posthead(
		"\\"
		/*"\textit{Summary measures for \`\`passing'' SI comprehension} \\" */
	
	) 
	cells("mean(fmt(%9.2f))" ) 
	;
#d cr

// Last line (with observations)
su acasi_screening_pass5 if survey=="gd_mw_endline" & !mi(acasi_ipv_treat) 
global obs_mw `r(N)'

su acasi_screening_pass5 if survey=="gd_lrw2_endline" & !mi(acasi_ipv_treat) 
global obs_lrw2 `r(N)'
	
#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label 
	prefoot(
		"\midrule"
		"Observations & `:display %5.0fc ${obs_mw}' & `:display %5.0fc ${obs_lrw2}' \\ "
		)
	postfoot("\bottomrule" "\end{tabular}")
	;
#d cr	
*******************************************************************************/

	/******************** Stata program *********************/
	cap program drop running_regressions_pnp
	program running_regressions_pnp
		syntax, yvarlist(string) i(string) controls(string)

	gen ACASI_nonscreenpass  = (acasi_ipv_treat==1) & (acasi_screening_pass==0) if !mi(acasi_ipv_treat) & !mi(acasi_screening_pass)		
	gen ACASI_screenpass     = (acasi_ipv_treat==1) & (acasi_screening_pass==1) if !mi(acasi_ipv_treat) & !mi(acasi_screening_pass)
		
	foreach yvar in `yvarlist' {
		local ++i
		eststo est_`i': reg `yvar' ACASI_screenpass ACASI_nonscreenpass acasi_screening_pass `controls' i.countrysample, cluster(id)
			
			// Differences 
			test (ACASI_nonscreenpass = ACASI_screenpass)
			estadd scalar diff_pval= r(p)		

			// Pooled effects
			su acasi_screening_pass if e(sample)
			local screenpass_mean = `r(mean)'
			local nonscreenpass_mean = 1 - `screenpass_mean'

			estadd scalar pooled_effect_b = _b[ACASI_nonscreenpass]*`nonscreenpass_mean' + _b[ACASI_screenpass]*`screenpass_mean'
			test ACASI_nonscreenpass*`nonscreenpass_mean' + ACASI_screenpass*`screenpass_mean' = 0
			estadd scalar pooled_effect_pval = r(p)				

			// Control mean
			su `yvar' if acasi_ipv_treat==0 & acasi_screening_pass==0
			estadd scalar controlmean_ftfi = r(mean)							
			
			// Number of respondents
			distinct id if e(sample)==1
			estadd scalar num_resp = r(ndistinct)
	}
	end
	/********************************************************/
	
	/******************** Stata program *********************/
	cap program drop exporting_results_pnp
	program exporting_results_pnp
		syntax, texname(string) replace_append(string) number(string) prehead(string) posthead(string) numcol(string)
	
	#d;
	estout * using "${raw_folder}/`texname'.tex", `replace_append' style(tex) mlabel(none) collabel(none) `number' label 
		starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" 2 " "")	
		prehead(`prehead')
		posthead(`posthead') 
		keep(ACASI_screenpass ACASI_nonscreenpass acasi_screening_pass) varlabel(
			ACASI_nonscreenpass "SI $\times$ Non-pass ($\gamma$)" 
			ACASI_screenpass "SI $\times$ Comprehension Pass ($\beta$)" 
			acasi_screening_pass "Comprehension Pass")
		cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
		prefoot("\\")	
		stats(controlmean_ftfi diff_pval N, fmt(%9.2fc %9.3fc %9.0fc)
		labels(
			"FTFI $\times$ Non-pass mean" 
			"\emph{p}-value ($\beta=\gamma$)"
			"Observations"
			)) 
		;
	#d cr
	
		// Post-estimation calculation of total effects
		#d;
		estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label 
			drop(*)
			prefoot("\\" "\multicolumn{`numcol'}{l}{\textit{Effect of SI for the average respondent}} \\")	
			stats(
				pooled_effect_b pooled_effect_pval 
				, 
				fmt(%9.2fc %9.3fc) 
				labels(
					"Pooled SI effects" "\quad \emph{p}-value"
					)) 
			;
		#d cr
		
	end
	/********************************************************/	
	
	/******************** Stata program *********************/
	cap program drop exporting_results_pnp_nopooled
	program exporting_results_pnp_nopooled
		syntax, texname(string) replace_append(string) number(string) prehead(string) posthead(string) numcol(string)
	
	#d;
	estout * using "${raw_folder}/`texname'.tex", `replace_append' style(tex) mlabel(none) collabel(none) `number' label 
		starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" 2 " "")	
		prehead(`prehead')
		posthead(`posthead') 
		keep(ACASI_screenpass ACASI_nonscreenpass acasi_screening_pass) varlabel(
			ACASI_nonscreenpass "SI $\times$ Non-pass ($\gamma$)" 
			ACASI_screenpass "SI $\times$ Comprehension Pass ($\beta$)" 
			acasi_screening_pass "Comprehension Pass")
		cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
		prefoot("\\")	
		stats(controlmean_ftfi diff_pval N, fmt(%9.2fc %9.3fc %9.0fc)
		labels(
			"FTFI $\times$ Non-pass mean" 
			"\emph{p}-value ($\beta=\gamma$)"
			"Observations"
			)) 
		;
	#d cr
			
	end
	/********************************************************/		

		/******************** Stata program *********************/
		cap program drop exporting_results_pnp_nopooled_d
		program exporting_results_pnp_nopooled_d
			syntax, texname(string) replace_append(string) number(string) prehead(string) posthead(string) numcol(string)
		
		#d;
		estout * using "${raw_folder}/`texname'.tex", `replace_append' style(tex) mlabel(none) collabel(none) `number' label 
			starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" 2 " "")	
			prehead(`prehead')
			posthead(`posthead') 
			keep(ACASI_screenpass ACASI_nonscreenpass acasi_screening_pass) varlabel(
				ACASI_nonscreenpass "SI $\times$ Non-pass ($\gamma$)" 
				ACASI_screenpass "SI $\times$  Pass ($\beta$)" 
				acasi_screening_pass " Pass")
			cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
			prefoot("\\")	
			stats(controlmean_ftfi diff_pval N, fmt(%9.2fc %9.3fc %9.0fc)
			labels(
				"FTFI $\times$ Non-pass mean" 
				"\emph{p}-value ($\beta=\gamma$)"
				"Observations"
				)) 
			;
		#d cr
				
		end
		/********************************************************/		
	
	/******************** Stata program *********************/
	cap program drop running_regressions
	program running_regressions
		syntax, yvarlist(string) i(string) controls(string)
	
	foreach yvar in `yvarlist' {
		local ++i
		eststo est_`i': reg `yvar' acasi_ipv_treat `controls' i.countrysample, cluster(id)
			
			// Control mean
			su `yvar' if acasi_ipv_treat==0 
			estadd scalar controlmean = r(mean)								
	}
	
	end
	/********************************************************/

	/******************** Stata program *********************/
	cap program drop running_regressions_enumFE
	program running_regressions_enumFE
		syntax, yvarlist(string) i(string) controls(string)
	
	foreach yvar in `yvarlist' {
		local ++i
		eststo est_`i': reg `yvar' acasi_ipv_treat `controls' i.countrysample i.country_enumerator, cluster(id)
			
			// Control mean
			su `yvar' if acasi_ipv_treat==0 
			estadd scalar controlmean = r(mean)								
	}
	
	end
	/********************************************************/

	
	/******************** Stata program *********************/
	cap program drop exporting_results
	program exporting_results
		syntax, texname(string) replace_append(string) number(string) prehead(string) posthead(string) numcol(string)
	
	#d;
	estout * using "${raw_folder}/`texname'.tex", `replace_append' style(tex) mlabel(none) collabel(none) `number' label 
		starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" 2 " "")	
		prehead(`prehead')
		posthead(`posthead') 
		keep(acasi_ipv_treat) varlabel(acasi_ipv_treat "SI")
		cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
		prefoot("\\")	
		stats(controlmean N, fmt(%9.2fc %9.0fc)	labels("FTFI mean" "Observations"))  
		;
	#d cr
		
	end
	/********************************************************/		

	/******************** Stata program *********************/
	cap program drop running_regressions_qlevel
	program running_regressions_qlevel
		syntax, i(string) controls(string)
	
	// By category (ctrl, emo, phy, sex)
	local yvarlist ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q
	
	preserve
	keep id enumerator acasi_ipv_treat acasi_yesfirst ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q? `controls' countrysample country_enumerator 
	reshape long ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q, i(id) j(q)

	foreach yvar in `yvarlist' {
		local ++i
		eststo est_`i': reg `yvar' acasi_ipv_treat `controls' i.countrysample i.q, cluster(id)
			
			// Control mean
			su `yvar' if acasi_ipv_treat==0
			estadd scalar controlmean = r(mean)							
			
			// Number of respondents
			distinct id if e(sample)==1
			estadd scalar num_resp = r(ndistinct)
	}
	restore
	
	// All questions pooled
	local yvarlist ipv_var
	ds ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q?
	local i 0
	foreach ipv_var in `r(varlist)' {
		local ++i
		rename `ipv_var' ipv_var`i'
	}
	keep id enumerator acasi_ipv_treat ipv_var* `controls' countrysample country_enumerator 
	reshape long ipv_var, i(id) j(q)

	foreach yvar in `yvarlist' {
		local ++i
		eststo est_`i': reg `yvar' acasi_ipv_treat `controls' i.countrysample i.q, cluster(id)
			
			// Control mean
			su `yvar' if acasi_ipv_treat==0
			estadd scalar controlmean = r(mean)							
			
			// Number of respondents
			distinct id if e(sample)==1
			estadd scalar num_resp = r(ndistinct)
	}
	
	end
	/********************************************************/

	/******************** Stata program *********************/
	cap program drop running_regressions_q_enumFE
	program running_regressions_q_enumFE
		syntax, i(string) controls(string)
	
	// By category (ctrl, emo, phy, sex)
	local yvarlist ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q
	
	preserve
	keep id enumerator acasi_ipv_treat acasi_yesfirst ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q? `controls' countrysample country_enumerator 
	reshape long ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q, i(id) j(q)

	foreach yvar in `yvarlist' {
		local ++i
		eststo est_`i': reg `yvar' acasi_ipv_treat `controls' i.countrysample i.q i.country_enumerator, cluster(id)
			
			// Control mean
			su `yvar' if acasi_ipv_treat==0
			estadd scalar controlmean = r(mean)							
			
			// Number of respondents
			distinct id if e(sample)==1
			estadd scalar num_resp = r(ndistinct)
	}
	restore
	
	// All questions pooled
	local yvarlist ipv_var
	ds ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q?
	local i 0
	foreach ipv_var in `r(varlist)' {
		local ++i
		rename `ipv_var' ipv_var`i'
	}
	keep id enumerator acasi_ipv_treat ipv_var* `controls' countrysample country_enumerator 
	reshape long ipv_var, i(id) j(q)

	foreach yvar in `yvarlist' {
		local ++i
		eststo est_`i': reg `yvar' acasi_ipv_treat `controls' i.countrysample i.q i.country_enumerator, cluster(id)
			
			// Control mean
			su `yvar' if acasi_ipv_treat==0
			estadd scalar controlmean = r(mean)							
			
			// Number of respondents
			distinct id if e(sample)==1
			estadd scalar num_resp = r(ndistinct)
	}
	
	end
	/********************************************************/
	
	/******************** Stata program *********************/
	cap program drop exporting_results_qlevel
	program exporting_results_qlevel
		syntax, texname(string) replace_append(string) number(string) prehead(string) posthead(string) numcol(string)
	
	#d;
	estout * using "${raw_folder}/`texname'.tex", `replace_append' style(tex) mlabel(none) collabel(none) `number' label 
		starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") 	
		prehead(`prehead')
		posthead(`posthead') 	
		keep(acasi_ipv_treat) varlabel(acasi_ipv_treat "SI")
		cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
		prefoot("\\")	
		stats(controlmean num_resp N, fmt(%9.2fc %9.0fc %9.0fc) labels("FTFI mean" "Number of individuals" "Observations")) 
		;
	#d cr
			
	end
	/********************************************************/	

/*******************************************************************************
 Table 3: Effect of Self-interviewing (SI) on Placebo Questions
*******************************************************************************/
local texname table3
local yvarlist acasi_placebo_q3 acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \begin{tabular}{c} Farm work \\ (past year) \end{tabular} &\begin{tabular}{c}  Market visit \\ (past week) \end{tabular}  & \begin{tabular}{c} Maize/Rice \\ (next week) \end{tabular} & \begin{tabular}{c} Meat \\ (next week) \end{tabular} \\"
	
// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\");
#d cr

// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")										
*******************************************************************************/

/*******************************************************************************
 Table 4: Effect of Self-interviewing (SI) on Placebo Questions, 
          Heterogeneity by "Passing" the Comprehension Section 
*******************************************************************************/
local texname table4
local yvarlist acasi_placebo_q3 acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \begin{tabular}{c} Farm work \\ (past year) \end{tabular} &\begin{tabular}{c}  Market visit \\ (past week) \end{tabular}  & \begin{tabular}{c} Maize/Rice \\ (next week) \end{tabular} & \begin{tabular}{c} Meat \\ (next week) \end{tabular} \\"
	
// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"
cap drop acasi_screening_pass
rename acasi_screening_pass3 acasi_screening_pass

est clear
running_regressions_pnp, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results_pnp_nopooled, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"
cap drop acasi_screening_pass
rename acasi_screening_pass3 acasi_screening_pass

est clear
running_regressions_pnp, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results_pnp_nopooled, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\");
#d cr

// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")										
*******************************************************************************/

/*******************************************************************************
 Table 5: Effect of Self-interviewing (SI) on IPV (Individual Questions)
*******************************************************************************/
local texname table5
local numcol 5
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \multicolumn{4}{c}{\scriptsize =1 if responded yes to \emph{individual} question in the following category:} & \multirow{3}{*}{\begin{tabular}{c} All \\ questions \\ pooled \end{tabular} } \\ " ///
	"\cmidrule(lr){2-5}" ///
	" & \begin{tabular}{c} Controlling \\ Behavior \end{tabular} & \begin{tabular}{c} Emotional \\ IPV \end{tabular} & \begin{tabular}{c} Physical \\ IPV \end{tabular} & \begin{tabular}{c} Sexual \\ IPV \end{tabular} & \\" 

// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"

est clear
running_regressions_qlevel, i(0) controls(${controls_rm})

#d;
exporting_results_qlevel, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"

est clear
running_regressions_qlevel, i(0) controls(${controls_rm})

#d;
exporting_results_qlevel, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr
	
// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")		
*******************************************************************************/


/*******************************************************************************
 Table 6: Effect of Self-interviewing (SI) on IPV Indices
*******************************************************************************/
local texname table6
local yvarlist ctrl_bx ipv_emo ipv_phy ipv_sex ipv_any 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \multicolumn{4}{c}{\scriptsize  =1 if responded yes to \textit{at least one} question in the following category:} & \multirow{3}{*}{\begin{tabular}{c} Any \\ IPV  \end{tabular} } \\ " ///
	"\cmidrule(lr){2-5}" ///
	" & \begin{tabular}{c} Controlling \\ Behavior \end{tabular} & \begin{tabular}{c} Emotional \\ IPV \end{tabular} & \begin{tabular}{c} Physical \\ IPV \end{tabular} & \begin{tabular}{c} Sexual \\ IPV \end{tabular} & \\" 
			
// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr
	
// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")		
*******************************************************************************/


/************************************************************************************************************************
													Appendix Tables
************************************************************************************************************************/

/*******************************************************************************
 Table A2: Balance Check in Sample Exclusion 
*******************************************************************************/
local texname tableA2

use "replicationData.dta", clear
drop if survey=="gd_lrw1_endline"
drop acasi_ipv_treat_0

gen acasi_ipv_treat_0 = acasi_rand_group<=.5 if ipv_surveyed==1 // original ACASI treatment assignment
gen acasi_ipv_treat_2 = acasi_rand_group<=.5 if ipv_surveyed==1 & hearing_seeing_giveup!=1 // exclusion: those who have hearing/seeing problems

	// Refused EVERY IPV questions
	gen ipv_refused_all = 	///
	   (ipv_emo_q1==.r & ipv_emo_q2==.r & ipv_emo_q3==.r & ipv_emo_q4==.r & ///
		ipv_phy_q1==.r & ipv_phy_q2==.r & ipv_phy_q3==.r & ipv_phy_q4==.r & ipv_phy_q5==.r & ipv_phy_q6==.r & ///
		ipv_sex_q1==.r & ipv_sex_q2==.r & ipv_sex_q3==.r) ///
		if ipv_surveyed==1
		
	// Hearing/seeing difficulties
	replace hearing_seeing=0 if mi(hearing_seeing)

est clear
foreach YYY in ipv_refused_all hearing_seeing {
	eststo : reg `YYY' acasi_ipv_treat_0 i.countrysample, cluster(id) // not including controls
		su `YYY' if acasi_ipv_treat_0==0
		estadd scalar controlmean = r(mean)
}
#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) number label 
	starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" 2 " "")	
	prehead("\begin{tabular}{l *{2}{c}}" "\toprule")
	posthead(
		" & \begin{tabular}{c} Refused to all \\ IPV questions \end{tabular} & \begin{tabular}{c} Dropped due to \\ vision/hearing impairment \end{tabular} \\"
		"\midrule"
		) 
	keep(acasi_ipv_treat_0) varlabel(acasi_ipv_treat_0 "Experimentally assigned to ACASI")
	cells("b(fmt(%9.3f) star)" "se(fmt(%9.3f) par)") 
	prefoot("\\")	
	stats(controlmean N, fmt(%9.3fc %9.0fc)	labels("FTFI mean" "Observations"))  
	postfoot("\bottomrule" "\end{tabular}")
	;
#d cr
*******************************************************************************/


/*******************************************************************************
 Table A3: Correlates of "Passing" SI Comprehension Questions
*******************************************************************************/
local texname tableA3
local yvarlist acasi_screening_pass

	/******************** Stata program *********************/
	cap program drop exporting_results_3dec
	program exporting_results_3dec
		syntax, texname(string) replace_append(string) number(string) prehead(string) posthead(string) numcol(string)
	
	#d;
	estout * using "${raw_folder}/`texname'.tex", `replace_append' style(tex) mlabel(none) collabel(none) `number' label 
		starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" 2 " "")	
		prehead(`prehead')
		posthead(`posthead') 
		keep(acasi_ipv_treat) varlabel(acasi_ipv_treat "SI")
		cells("b(fmt(%9.3f) star)" "se(fmt(%9.3f) par)") 
		prefoot("\\")	
		stats(controlmean N, fmt(%9.3fc %9.0fc)	labels("FTFI mean" "Observations"))  
		;
	#d cr
		
	end
	/********************************************************/
	
use "replicationData.dta", clear
rename acasi_screening_pass3 acasi_screening_pass

keep if acasi_screening
keep if !mi(acasi_ipv_treat) // keeping only those who were part of the ACASI/FTF for IPV questions (e.g. excluding men, etc.)

// Univariate regressions
local xvarlist	ipv_years_educ ipv_eng_readorwrite mobile_phone 
	
lab var ipv_years_educ_r		"Years of education"
lab var ipv_eng_readorwrite_r	"=1 if able to write/read"
lab var mobile_phone_r			"=1 if has access to mobile phone"

est clear
foreach surveysample in gd_mw_endline gd_lrw2_endline  {
	local xvarlist_all
	foreach xvar in `xvarlist' {
		eststo : reg acasi_screening_pass `xvar'_r `xvar'_m if survey=="`surveysample'", cluster(id)
			su acasi_screening_pass if survey=="`surveysample'"
			estadd scalar overallmean = r(mean)				
		local xvarlist_all `xvarlist_all' `xvar'_r `xvar'_m
	}
		eststo : reg acasi_screening_pass ${controls_rm} if survey=="`surveysample'", cluster(id)
			su acasi_screening_pass if survey=="`surveysample'"
			estadd scalar overallmean = r(mean)				
}

#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) number label 
	keep(ipv_years_educ_r ipv_eng_readorwrite_r mobile_phone_r) starlevels(* 0.10 ** 0.05 *** 0.01)			
	prehead("\begin{tabular}{l *{8}{c}}" "\toprule")
	posthead(
		" & \multicolumn{8}{c}{=1 if passed SI comprehension\tnote{a}} \\"
		"\cmidrule(lr){2-9}"
		" & \multicolumn{4}{c}{Malawi} & \multicolumn{4}{c}{Liberia} \\"
		"\cmidrule(lr){2-5}\cmidrule(lr){6-9}"
		"\midrule"
		) 	
	cells("b(fmt(%9.3f) star)" "se(fmt(%9.3f) par)") 
	prefoot("\\")
	stats(r2 overallmean N, labels("R-squared" "Mean of dependent variable" "Observations") fmt(%9.3fc %9.2fc %9.0fc))  
	postfoot("\bottomrule" "\end{tabular}")					
	;
#d cr
*******************************************************************************/

/*******************************************************************************
 Table A4: Effect of SI on Choosing "Don't know" or "Refuse to answer" in Placebo Questions
*******************************************************************************/
local texname tableA4
local yvarlist_raw acasi_placebo_q3  acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 
local numcol = wordcount("`yvarlist_raw'")
local latex_header ///
	" & \begin{tabular}{c} Farm work \\ (past year) \end{tabular} &\begin{tabular}{c}  Market visit \\ (past week) \end{tabular}  & \begin{tabular}{c} Maize/Rice \\ (next week) \end{tabular} & \begin{tabular}{c} Meat \\ (next week) \end{tabular} \\"

use "replicationData.dta", clear

local yvarlist ""
foreach yvar in `yvarlist_raw' {
	gen `yvar'_dkrf = (`yvar'==.d | `yvar'==.r) if !mi(acasi_ipv_treat)
	local yvarlist `yvarlist' `yvar'_dkrf
}

// Panel A. Malawi
local panel_text "Panel A. Malawi"

preserve
keep if survey=="gd_mw_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results_3dec, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr
restore

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

preserve
keep if survey=="gd_lrw2_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results_3dec, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr
restore
	
// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")	
*******************************************************************************/
	
	
		/******************** Stata program *********************/
		cap program drop acasi_subgroup_reg
		program acasi_subgroup_reg
			syntax, yvarlist(string) subgroup_var(string) i(string) controls(string)
		
		gen ACASI_subgroup  	= (acasi_ipv_treat==1) & (`subgroup_var'==1) if !mi(acasi_ipv_treat) & !mi(`subgroup_var')		
		gen ACASI_nonsubgroup 	= (acasi_ipv_treat==1) & (`subgroup_var'==0) if !mi(acasi_ipv_treat) & !mi(`subgroup_var')
		
		foreach yvar in `yvarlist' {
			local ++i
			eststo est_`i': reg `yvar' ACASI_subgroup ACASI_nonsubgroup `subgroup_var' `controls' i.countrysample, cluster(id)
			
				// Differences
				test  _b[ACASI_subgroup] = _b[ACASI_nonsubgroup] 
				estadd scalar diff_pval= r(p)		
				
				// Control mean
				su `yvar' if acasi_ipv_treat==0 & `subgroup_var'==0
				estadd scalar controlmean = r(mean)				
		}
		end
		/********************************************************/
	
		/******************** Stata program *********************/
		cap program drop acasi_subgroup_export
		program acasi_subgroup_export
			syntax, texname(string) replace_append(string) number(string) prehead(string) posthead(string) subgroup_var(string) subgroup_text(string) subgroup_ctrl_text(string)

		#d;
		estout * using "${raw_folder}/`texname'.tex", `replace_append' style(tex) mlabel(none) collabel(none) `number' label 
			starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" . " "")	noomit
			prehead(`prehead')
			posthead(`posthead') 
			keep(ACASI_subgroup ACASI_nonsubgroup `subgroup_var') varlabel(ACASI_subgroup "SI $\times$ `subgroup_text' ($\beta$)" ACASI_nonsubgroup "SI $\times$ `subgroup_ctrl_text' ($\gamma$)" `subgroup_var' "`subgroup_text'")
			cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
			prefoot("\\")	
			stats(controlmean diff_pval N, fmt(%9.2fc %9.3fc %9.0fc) labels("FTFI $\times$ `subgroup_ctrl_text' mean" "\emph{p}-value ($\beta = \gamma$)" "Observations")) 			
			;
		#d cr
		end
		/********************************************************/	


/*******************************************************************************
 Table A5: Heterogeneity in Effects of ACASI on Placebo Questions (Malawi)
*******************************************************************************/
local texname tableA5
local yvarlist acasi_placebo_q3 acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \begin{tabular}{c} Farm work \\ (past year) \end{tabular} &\begin{tabular}{c}  Market visit \\ (past week) \end{tabular}  & \begin{tabular}{c} Maize/Rice \\ (next week) \end{tabular} & \begin{tabular}{c} Meat \\ (next week) \end{tabular} \\"
	
// Panel A
local panel_text "Panel A. Primary education completion"
local subgroup_var primary_complete
local subgroup_text "Primary Educ"
local subgroup_ctrl_text "No Primary Educ"

use "replicationData.dta", clear
keep if gd_mw

est clear		
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm})

#d;
acasi_subgroup_export, texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text') replace_append("replace") number("number") 
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead(
		"`latex_header'"
		"\midrule"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr		
		
// Panel B
local panel_text "Panel B. Access to mobile phone"
local subgroup_var mobile_phone_r
local subgroup_text "Mobile"
local subgroup_ctrl_text "No Mobile"

use "replicationData.dta", clear
keep if gd_mw

est clear		
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm})

#d;
acasi_subgroup_export, replace_append("append") number(" ") texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text')  
	prehead(" ") 
	posthead(
		"\\"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr

// Panel C
local panel_text "Panel C. Able to read/write"
local subgroup_var ipv_eng_readorwrite_r
local subgroup_text "English"
local subgroup_ctrl_text "No English"

use "replicationData.dta", clear
keep if gd_mw

est clear		
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm})

#d;
acasi_subgroup_export, replace_append("append") number(" ") texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text')  
	prehead(" ") 
	posthead(
		"\\"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr

// Panel D
local panel_text "Panel D. Age"
local subgroup_var age_below50p
local subgroup_text "Below-median Age"
local subgroup_ctrl_text "Above-median Age"

use "replicationData.dta", clear
keep if gd_mw

su age_r, d
gen age_below50p = age_r<`r(p50)' if !mi(age_r)

est clear		
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm})

#d;
acasi_subgroup_export, replace_append("append") number(" ") texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text')  
	prehead(" ") 
	posthead(
		"\\"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr

// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")				
*******************************************************************************/
	

/*******************************************************************************
 Table A6: Heterogeneity in Effects of ACASI on Placebo Questions (Liberia)
*******************************************************************************/
local texname tableA6
local yvarlist acasi_placebo_q3 acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \begin{tabular}{c} Farm work \\ (past year) \end{tabular} &\begin{tabular}{c}  Market visit \\ (past week) \end{tabular}  & \begin{tabular}{c} Maize/Rice \\ (next week) \end{tabular} & \begin{tabular}{c} Meat \\ (next week) \end{tabular} \\"

// Panel A
local panel_text "Panel A. Primary education completion"
local subgroup_var primary_complete
local subgroup_text "Primary Educ"
local subgroup_ctrl_text "No Primary Educ"

use "replicationData.dta", clear
keep if gd_lrw2

est clear		
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm})

#d;
acasi_subgroup_export, texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text') replace_append("replace") number("number") 
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead(
		"`latex_header'"
		"\midrule"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr		
		
// Panel B
local panel_text "Panel B. Access to mobile phone"
local subgroup_var mobile_phone_r
local subgroup_text "Mobile"
local subgroup_ctrl_text "No Mobile"

use "replicationData.dta", clear
keep if gd_lrw2

est clear		
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm})

#d;
acasi_subgroup_export, replace_append("append") number(" ") texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text')  
	prehead(" ") 
	posthead(
		"\\"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr

// Panel C
local panel_text "Panel C. Able to read/write"
local subgroup_var ipv_eng_readorwrite_r
local subgroup_text "English"
local subgroup_ctrl_text "No English"

use "replicationData.dta", clear
keep if gd_lrw2

est clear		
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm})

#d;
acasi_subgroup_export, replace_append("append") number(" ") texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text')  
	prehead(" ") 
	posthead(
		"\\"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr

// Panel D
local panel_text "Panel D. Age"
local subgroup_var age_below50p
local subgroup_text "Below-median Age"
local subgroup_ctrl_text "Above-median Age"

use "replicationData.dta", clear
keep if gd_lrw2

su age_r, d
gen age_below50p = age_r<`r(p50)' if !mi(age_r)

est clear		
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm})

#d;
acasi_subgroup_export, replace_append("append") number(" ") texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text')  
	prehead(" ") 
	posthead(
		"\\"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr	

// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")				
*******************************************************************************/

/*******************************************************************************
 Table A7: Effect of ACASI on Choosing "Don't know" or "Refuse to answer" in IPV Questions
*******************************************************************************/
local texname tableA7
local numcol 5
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \multicolumn{4}{c}{\scriptsize =1 if don't know or refusal to \emph{individual} question in following category:} & \multirow{3}{*}{\begin{tabular}{c} All \\ questions \\ pooled \end{tabular} } \\ " ///
	"\cmidrule(lr){2-5}" ///
	" & \begin{tabular}{c} Controlling \\ Behavior \end{tabular} & \begin{tabular}{c} Emotional \\ IPV \end{tabular} & \begin{tabular}{c} Physical \\ IPV \end{tabular} & \begin{tabular}{c} Sexual \\ IPV \end{tabular} & \\" 

	/******************** Stata program *********************/
	cap program drop running_regressions_dkrf_qlevel
	program running_regressions_dkrf_qlevel
		syntax, i(string)
	
	// By category (ctrl, emo, phy, sex)
	local yvarlist ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q
	
	preserve
	keep id enumerator acasi_ipv_treat ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q? ${controls_rm} countrysample country_enumerator 
	reshape long ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q, i(id) j(q)
	
	foreach yvar in `yvarlist' {
		local ++i
		
		gen `yvar'_dkrf = (`yvar'==.d | `yvar'==.r) if !mi(acasi_ipv_treat)
		eststo est_`i': reg `yvar'_dkrf acasi_ipv_treat ${controls_rm} i.countrysample i.q, cluster(id)
			
			// Control mean
			su `yvar'_dkrf if acasi_ipv_treat==0
			estadd scalar controlmean = r(mean)							
			
			// Number of respondents
			distinct id if e(sample)==1
			estadd scalar num_resp = r(ndistinct)
	}
	restore
	
	// All questions pooled
	local yvarlist ipv_var
	ds ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q?
	local i 0
	foreach ipv_var in `r(varlist)' {
		local ++i
		rename `ipv_var' ipv_var`i'
	}
	keep id enumerator acasi_ipv_treat ipv_var* ${controls_rm} countrysample country_enumerator 
	reshape long ipv_var, i(id) j(q)

	foreach yvar in `yvarlist' {
		local ++i
		gen `yvar'_dkrf = (`yvar'==.d | `yvar'==.r) if !mi(acasi_ipv_treat)
		eststo est_`i': reg `yvar'_dkrf acasi_ipv_treat ${controls_rm} i.countrysample i.q, cluster(id)
			
			// Control mean
			su `yvar'_dkrf if acasi_ipv_treat==0 & e(sample)==1
			estadd scalar controlmean = r(mean)							
			
			// Number of respondents
			distinct id if e(sample)==1
			estadd scalar num_resp = r(ndistinct)
	}
	
	end
	/********************************************************/

	/******************** Stata program *********************/
	cap program drop exporting_results_dkrf_qlevel
	program exporting_results_dkrf_qlevel
		syntax, texname(string) replace_append(string) number(string) prehead(string) posthead(string) numcol(string)
	
	#d;
	estout * using "${raw_folder}/`texname'.tex", `replace_append' style(tex) mlabel(none) collabel(none) `number' label 
		starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") 	
		prehead(`prehead')
		posthead(`posthead') 	
		keep(acasi_ipv_treat) varlabel(acasi_ipv_treat "SI")
		cells("b(fmt(%9.3f) star)" "se(fmt(%9.3f) par)") 
		prefoot("\\")	
		stats(controlmean num_resp N, fmt(%9.3fc %9.0fc %9.0fc) labels("FTFI mean" "Number of individuals" "Observations")) 
		;
	#d cr
			
	end
	/********************************************************/	

// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear

keep if survey=="gd_mw_endline"

est clear
running_regressions_dkrf_qlevel, i(0)

#d;
exporting_results_dkrf_qlevel, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear

keep if survey=="gd_lrw2_endline"

est clear
running_regressions_dkrf_qlevel, i(0)

#d;
exporting_results_dkrf_qlevel, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr
	
// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")		
*******************************************************************************/


/*******************************************************************************
 Table B1: Debriefing Survey on Technical Issues with ACASI Module
*******************************************************************************/
local texname tableB1
local yvarlist ipv_volume ipv_speed_okay 

use "replicationData.dta", clear

est clear
eststo : estpost su `yvarlist' if gd_mw		& acasi_ipv_treat==1
eststo : estpost su `yvarlist' if gd_lrw2	& acasi_ipv_treat==1

lab var ipv_volume		"Was the audio loud enough to hear?"
lab var ipv_speed_okay	"Was the audio speaking speed okay?"

#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) number label 
	prehead("\begin{tabular}{l *{2}{c}}" "\toprule")
	posthead(
		" & \multicolumn{2}{c}{Mean (=1 if yes)} \\ "
		"\cmidrule(lr){2-3}"
		" & \multicolumn{1}{c}{Malawi} & \multicolumn{1}{c}{Liberia}\\"
		"\midrule"
		) 
	cells("mean(fmt(%9.2f))" ) 
	;
#d cr

// Last line (with Observations)
su ipv_volume if gd_mw 		& acasi_ipv_treat==1  
global obs_mw `r(N)'
su ipv_volume if gd_lrw2 	& acasi_ipv_treat==1 
global obs_lrw2 `r(N)'

#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label 
	prefoot(
		"\midrule"
		"Observations & `:display %5.0fc ${obs_mw}' & `:display %5.0fc ${obs_lrw2}'\\ "
		)
	postfoot("\bottomrule" "\end{tabular}")
	;
#d cr	
*******************************************************************************/

/*******************************************************************************
 Table B2: Relationship between Reporting Technical Difficulties and Passing Screening
*******************************************************************************/
local texname tableB2
local xvarlist	ipv_volume ipv_speed_okay 

use "replicationData.dta", clear
	
lab var ipv_volume		"audio loud enough to hear"
lab var ipv_speed_okay	"audio speaking speed okay"

est clear
foreach surveysample in gd_mw_endline gd_lrw2_endline  {
	foreach xvar in `xvarlist' {
		eststo : reg acasi_screening_pass3 `xvar' if survey=="`surveysample'", cluster(id)
			su acasi_screening_pass3 if `xvar'==0 & e(sample)
			estadd scalar controlmean = r(mean)				
	}
}

#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) number label 
	keep(ipv_volume ipv_speed_okay) starlevels(* 0.10 ** 0.05 *** 0.01)			
	prehead("\begin{tabular}{l *{4}{c}}" "\toprule")
	posthead(
		" & \multicolumn{4}{c}{=1 if passed SI comprehension\tnote{a}} \\"
		"\cmidrule(lr){2-5}"
		" & \multicolumn{2}{c}{Malawi} & \multicolumn{2}{c}{Liberia} \\"
		"\cmidrule(lr){2-3}\cmidrule(lr){4-5}"
		"\midrule"
		"=1 if said: \\"
		) 	
	cells("b(fmt(%9.3f) star)" "se(fmt(%9.3f) par)") 
	prefoot("\\")
	stats(r2 controlmean N, labels("R-squared" "Outcome mean when said no" "Observations") fmt(%9.3fc %9.2fc %9.0fc))  
	postfoot("\bottomrule" "\end{tabular}")					
	;
#d cr
*******************************************************************************/

/*******************************************************************************
 Table B3: Debriefing Survey on Comprehension Issues with ACASI Module
*******************************************************************************/
local texname tableB3
local yvarlist ipv_remembering ipv_selecting ipv_moving // ipv_words_acasi

est clear
eststo : estpost su `yvarlist' if gd_mw		& acasi_ipv_treat==1
eststo : estpost su `yvarlist' if gd_lrw2	& acasi_ipv_treat==1

lab var ipv_remembering	"Was it easy for you to remember the meaning of pictures?"
lab var ipv_selecting	"Was it easy for you to choose answers on the screen?"
lab var ipv_moving		"Was it easy for you to move between questions on the screen?"
lab var ipv_words_acasi	"Any words/questions you found hard to understand or didn't know?\tnote{a}"

#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) number label 
	prehead("\begin{tabular}{l *{2}{c}}" "\toprule")
	posthead(
		" & \multicolumn{2}{c}{Mean (=1 if yes)} \\ "
		"\cmidrule(lr){2-3}"
		" & \multicolumn{1}{c}{Malawi} & \multicolumn{1}{c}{Liberia}\\"
		"\midrule"
		) 
	cells("mean(fmt(%9.2f))" ) 
	;
#d cr

// Last line (with Observations)
su ipv_volume if gd_mw 		& acasi_ipv_treat==1  
global obs_mw `r(N)'
su ipv_volume if gd_lrw2 	& acasi_ipv_treat==1 
global obs_lrw2 `r(N)'

#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label 
	prefoot(
		"\midrule"
		"Observations & `:display %5.0fc ${obs_mw}' & `:display %5.0fc ${obs_lrw2}'\\ "
		)
	postfoot("\bottomrule" "\end{tabular}")
	;
#d cr	
*******************************************************************************/

/*******************************************************************************
 Table B4: Relationship between Reporting Comprehension and Passing Screening
*******************************************************************************/
local texname tableB4
local xvarlist ipv_remembering ipv_selecting ipv_moving 

use "replicationData.dta", clear
	
lab var ipv_remembering	"easy to remember the meaning of pictures"
lab var ipv_selecting	"easy to choose answers on screen"
lab var ipv_moving		"easy to move between questions on screen"

est clear
foreach surveysample in gd_mw_endline gd_lrw2_endline  {
	foreach xvar in `xvarlist' {
		eststo : reg acasi_screening_pass3 `xvar' if survey=="`surveysample'", cluster(id)
			su acasi_screening_pass3 if `xvar'==0 & e(sample)
			estadd scalar controlmean = r(mean)				
	}
}

#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) number label 
	keep(ipv_remembering ipv_selecting ipv_moving) starlevels(* 0.10 ** 0.05 *** 0.01)			
	prehead("\begin{tabular}{l *{6}{c}}" "\toprule")
	posthead(
		" & \multicolumn{6}{c}{=1 if passed SI comprehension\tnote{a}} \\"
		"\cmidrule(lr){2-7}"
		" & \multicolumn{3}{c}{Malawi} & \multicolumn{3}{c}{Liberia} \\"
		"\cmidrule(lr){2-4}\cmidrule(lr){5-7}"
		"\midrule"
		"=1 if said: \\"		
		) 	
	cells("b(fmt(%9.3f) star)" "se(fmt(%9.3f) par)") 
	prefoot("\\")
	stats(r2 controlmean N, labels("R-squared" "Outcome mean when said no" "Observations") fmt(%9.3fc %9.2fc %9.0fc))  
	postfoot("\bottomrule" "\end{tabular}")					
	;
#d cr
*******************************************************************************/

		/******************** Stata program *********************/
		cap program drop running_regressions_yesfirst
		program running_regressions_yesfirst
			syntax, yvarlist(string) i(string)

		local i = 0
		foreach yvar in `yvarlist' {
			local ++i
			eststo: reg `yvar' acasi_yesfirst ${controls_rm} i.countrysample, cluster(id) 
							
				// Control mean
				su `yvar' if acasi_yesfirst==0
				estadd scalar controlmean = r(mean)				
				
				distinct id if e(sample)==1
				estadd scalar num_resp = r(ndistinct)
		}
		
		end
		/********************************************************/

/*******************************************************************************
 Table C1: Effect of Ordering of Yes and No Options in ACASI on Placebo Questions
*******************************************************************************/
local texname tableC1
local yvarlist acasi_placebo_q3  acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \begin{tabular}{c} Farm work \\ (past year) \end{tabular} &\begin{tabular}{c}  Market visit \\ (past week) \end{tabular}  & \begin{tabular}{c} Maize/Rice \\ (next week) \end{tabular} & \begin{tabular}{c} Meat \\ (next week) \end{tabular} \\"

local subtreat_var acasi_yesfirst
local subtreat_text "YES First"

// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"
keep if acasi_ipv_treat==1

est clear
running_regressions_yesfirst, yvarlist(`yvarlist') i(0)

#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) number label 
	starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" . " "")	
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule")
	posthead(
		"`latex_header'" "\midrule"
		"\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\"
		)
	keep(acasi_yesfirst) varlabel(acasi_yesfirst "YES First" )
	cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
	prefoot("\\")	
	stats(controlmean N, fmt(%9.2fc %9.0fc) labels("NO First mean" "Observations"))  
	;
#d cr

// Panel B. Liberia (Wave 2)
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"
keep if acasi_ipv_treat==1

est clear
running_regressions_yesfirst, yvarlist(`yvarlist') i(0)

#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label 
	starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" . " "")	
	posthead(
		"\\"
		"\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\"
		)
	keep(acasi_yesfirst) varlabel(acasi_yesfirst "YES First" )
	cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
	prefoot("\\")	
	stats(controlmean N, fmt(%9.2fc %9.0fc) labels("NO First mean" "Observations"))  
	;
#d cr

// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")	
*******************************************************************************/


/*******************************************************************************
 Table C2: Effect of Ordering of Yes and No Options in ACASI on IPV Questions
*******************************************************************************/	
local texname tableC2
local yvarlist ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q
local numcol 5
local subtreat_var acasi_yesfirst
local subtreat_text "YES First"
local latex_header ///
	" & \multicolumn{4}{c}{\scriptsize =1 if responded yes to \emph{individual} question in the following category:} & \multirow{3}{*}{\begin{tabular}{c} All \\ questions \\ pooled \end{tabular} } \\ " ///
	"\cmidrule(lr){2-5}" ///
	" & \begin{tabular}{c} Controlling \\ Behavior \end{tabular} & \begin{tabular}{c} Emotional \\ IPV \end{tabular} & \begin{tabular}{c} Physical \\ IPV \end{tabular} & \begin{tabular}{c} Sexual \\ IPV \end{tabular} & \\" 


// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"
keep if acasi_ipv_treat==1

preserve
keep id enumerator acasi_ipv_treat acasi_yesfirst ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q? ${controls_rm} countrysample country_enumerator `subtreat_var'
reshape long ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q, i(id) j(q)

est clear
running_regressions_yesfirst, yvarlist(`yvarlist') i(0)
restore

	// All questions
	ds ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q?
	local i 0
	foreach ipv_var in `r(varlist)' {
		local ++i
		rename `ipv_var' ipv_var`i'
	}
	keep id enumerator acasi_ipv_treat ipv_var* ${controls_rm} countrysample country_enumerator `subtreat_var'  
	reshape long ipv_var, i(id) j(q)
	
	running_regressions_yesfirst, yvarlist(ipv_var) i(4)

#d;
estout * using "${raw_folder}/`texname'.tex", replace style(tex) mlabel(none) collabel(none) number label 
	starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" . " "")	
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule")
	posthead("`latex_header'" "\midrule"	"\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\") 
	keep(acasi_yesfirst) varlabel(acasi_yesfirst "YES First" )
	cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
	prefoot("\\")	
	stats(controlmean num_resp N, fmt(%9.2fc %9.0fc) labels("NO First mean" "Number of individuals" "Observations"))  
	;
#d cr

// Panel B. Liberia (Wave 2)
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"
keep if acasi_ipv_treat==1

preserve
keep id enumerator acasi_ipv_treat acasi_yesfirst ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q? ${controls_rm} countrysample country_enumerator `subtreat_var'
reshape long ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q, i(id) j(q)

est clear
running_regressions_yesfirst, yvarlist(`yvarlist') i(0)
restore

	// All questions
	ds ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q?
	local i 0
	foreach ipv_var in `r(varlist)' {
		local ++i
		rename `ipv_var' ipv_var`i'
	}
	keep id enumerator acasi_ipv_treat ipv_var* ${controls_rm} countrysample country_enumerator `subtreat_var'  
	reshape long ipv_var, i(id) j(q)
	
	running_regressions_yesfirst, yvarlist(ipv_var) i(4)
	
#d;
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) label 
	starlevels(* 0.10 ** 0.05 *** 0.01) dropped(" ") sub(" . " "")	
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\") 
	keep(acasi_yesfirst) varlabel(acasi_yesfirst "YES First" )
	cells("b(fmt(%9.2f) star)" "se(fmt(%9.2f) par)") 
	prefoot("\\")	
	stats(controlmean num_resp N, fmt(%9.2fc %9.0fc) labels("NO First mean" "Number of individuals" "Observations"))  
	;
#d cr

// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")	
*******************************************************************************/

/*******************************************************************************
 Table C3: Effect of Placebo Module Position on SI Effects for Placebo Questions
*******************************************************************************/
local texname tableC3
local yvarlist acasi_placebo_q3 acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \begin{tabular}{c} Farm work \\ (past year) \end{tabular} &\begin{tabular}{c}  Market visit \\ (past week) \end{tabular}  & \begin{tabular}{c} Maize/Rice \\ (next week) \end{tabular} & \begin{tabular}{c} Meat \\ (next week) \end{tabular} \\"
local subgroup_var acasi_placebofirst
local subgroup_text "Placebos First"
local subgroup_ctrl_text "IPV First"

// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"
egen ipv_later = rowmax(acasi_placebofirst phq_before_ipv)

est clear
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm} phq_before_ipv) // additionally controlling for the order b/w PHQ and IPV

#d;
acasi_subgroup_export, texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text') replace_append("replace") number("number") 
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead(
		"`latex_header'"
		"\midrule"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr

// Panel B. Liberia (Wave 2)
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"
egen ipv_later = rowmax(acasi_placebofirst phq_before_ipv)

est clear
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm} phq_before_ipv) // additionally controlling for the order b/w PHQ and IPV

#d;
acasi_subgroup_export, replace_append("append") number(" ") texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text')  
	prehead(" ") 
	posthead(
		"\\"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr

// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")	
*******************************************************************************/


/*******************************************************************************
 Table C4: Effect of Placebo Module Position on SI Effects for IPV Questions
*******************************************************************************/	
local texname tableC4
local yvarlist ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q
local numcol 5
local latex_header ///
	" & \multicolumn{4}{c}{\scriptsize =1 if responded yes to \emph{individual} question in the following category:} & \multirow{3}{*}{\begin{tabular}{c} All \\ questions \\ pooled \end{tabular} } \\ " ///
	"\cmidrule(lr){2-5}" ///
	" & \begin{tabular}{c} Controlling \\ Behavior \end{tabular} & \begin{tabular}{c} Emotional \\ IPV \end{tabular} & \begin{tabular}{c} Physical \\ IPV \end{tabular} & \begin{tabular}{c} Sexual \\ IPV \end{tabular} & \\" 
local subgroup_var acasi_placebofirst
local subgroup_text "Placebos First"
local subgroup_ctrl_text "IPV First"

// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"
egen ipv_later = rowmax(acasi_placebofirst phq_before_ipv)

preserve
keep id enumerator acasi_ipv_treat acasi_yesfirst acasi_placebofirst phq_before_ipv ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q? ${controls_rm} countrysample country_enumerator `subtreat_var'
reshape long ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q, i(id) j(q)

est clear
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm} phq_before_ipv) // additionally controlling for the order b/w PHQ and IPV
restore

	// All questions
	ds ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q?
	local i 0
	foreach ipv_var in `r(varlist)' {
		local ++i
		rename `ipv_var' ipv_var`i'
	}
	keep id enumerator acasi_ipv_treat acasi_placebofirst phq_before_ipv ipv_var* ${controls_rm} countrysample country_enumerator `subtreat_var'  
	reshape long ipv_var, i(id) j(q)
	
	acasi_subgroup_reg, yvarlist(ipv_var) subgroup_var(`subgroup_var') i(4) controls(${controls_rm} phq_before_ipv) // additionally controlling for the order b/w PHQ and IPV

#d;
acasi_subgroup_export, texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text') replace_append("replace") number("number") 
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead(
		"`latex_header'"
		"\midrule"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr	

// Panel B. Liberia (Wave 2)
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"
egen ipv_later = rowmax(acasi_placebofirst phq_before_ipv)

preserve
keep id enumerator acasi_ipv_treat acasi_yesfirst acasi_placebofirst phq_before_ipv ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q? ${controls_rm} countrysample country_enumerator `subtreat_var'
reshape long ctrl_bx_q ipv_emo_q ipv_phy_q ipv_sex_q, i(id) j(q)

est clear
acasi_subgroup_reg, yvarlist(`yvarlist') subgroup_var(`subgroup_var') i(0) controls(${controls_rm} phq_before_ipv) // additionally controlling for the order b/w PHQ and IPV
restore

	// All questions
	ds ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q?
	local i 0
	foreach ipv_var in `r(varlist)' {
		local ++i
		rename `ipv_var' ipv_var`i'
	}
	keep id enumerator acasi_ipv_treat acasi_placebofirst phq_before_ipv ipv_var* ${controls_rm} countrysample country_enumerator `subtreat_var'  
	reshape long ipv_var, i(id) j(q)
	
	acasi_subgroup_reg, yvarlist(ipv_var) subgroup_var(`subgroup_var') i(4) controls(${controls_rm} phq_before_ipv) // additionally controlling for the order b/w PHQ and IPV

#d;
acasi_subgroup_export, replace_append("append") number(" ") texname(`texname') subgroup_var(`subgroup_var') subgroup_text(`subgroup_text') subgroup_ctrl_text(`subgroup_ctrl_text')  
	prehead(" ") 
	posthead(
		"\\"
		"\multicolumn{`numcol'}{l}{\textbf{`panel_text'}} \\"
		) 
	;
#d cr
	
// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")	
*******************************************************************************/


/*******************************************************************************
 Table D1: Effect of Self-interviewing (SI) on Placebo Questions, no individual control
 - Table 3, no controls
*******************************************************************************/
local texname tableD1
local yvarlist acasi_placebo_q3 acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \begin{tabular}{c} Farm work \\ (past year) \end{tabular} &\begin{tabular}{c}  Market visit \\ (past week) \end{tabular}  & \begin{tabular}{c} Maize/Rice \\ (next week) \end{tabular} & \begin{tabular}{c} Meat \\ (next week) \end{tabular} \\"
	
// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"
cap drop acasi_screening_pass
rename acasi_screening_pass3 acasi_screening_pass

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(" ")

#d;
exporting_results, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"
cap drop acasi_screening_pass
rename acasi_screening_pass3 acasi_screening_pass

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(" ")

#d;
exporting_results, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\");
#d cr

// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")										
*******************************************************************************/

/*******************************************************************************
 Table D2: Effect of Self-interviewing (SI) on IPV Reporting in Individual Questions, no individual
controls
 - Table 4, no controls
*******************************************************************************/
local texname tableD2
local numcol 5
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \multicolumn{4}{c}{\scriptsize =1 if responded yes to \emph{individual} question in the following category:} & \multirow{3}{*}{\begin{tabular}{c} All \\ questions \\ pooled \end{tabular} } \\ " ///
	"\cmidrule(lr){2-5}" ///
	" & \begin{tabular}{c} Controlling \\ Behavior \end{tabular} & \begin{tabular}{c} Emotional \\ IPV \end{tabular} & \begin{tabular}{c} Physical \\ IPV \end{tabular} & \begin{tabular}{c} Sexual \\ IPV \end{tabular} & \\" 

// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"

est clear
running_regressions_qlevel, i(0) controls(" ")

#d;
exporting_results_qlevel, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"

est clear
running_regressions_qlevel, i(0) controls(" ")

#d;
exporting_results_qlevel, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr
	
// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")		
*******************************************************************************/

/*******************************************************************************
 Table D3: Effect of Self-interviewing (SI) on IPV Indices, no individual controls
*******************************************************************************/
local texname tableD3
local yvarlist ctrl_bx ipv_emo ipv_phy ipv_sex ipv_any 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \multicolumn{4}{c}{\scriptsize  =1 if responded yes to \textit{at least one} question in the following category:} & \multirow{3}{*}{\begin{tabular}{c} Any \\ IPV  \end{tabular} } \\ " ///
	"\cmidrule(lr){2-5}" ///
	" & \begin{tabular}{c} Controlling \\ Behavior \end{tabular} & \begin{tabular}{c} Emotional \\ IPV \end{tabular} & \begin{tabular}{c} Physical \\ IPV \end{tabular} & \begin{tabular}{c} Sexual \\ IPV \end{tabular} & \\" 
			
// Panel A. Malawi
local panel_text "Panel A. Malawi"

use "replicationData.dta", clear
keep if survey=="gd_mw_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(" ")

#d;
exporting_results, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use "replicationData.dta", clear
keep if survey=="gd_lrw2_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(" ")

#d;
exporting_results, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr
	
// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")		
*******************************************************************************/

	// Imputing zeroes for missing responses (i.e. "don't know" or "refuse to answer")
	use "replicationData.dta", clear

	local yvarlist acasi_placebo_q3 acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 ctrl_bx_q? ipv_emo_q? ipv_phy_q? ipv_sex_q? ctrl_bx ipv_emo ipv_phy ipv_sex ipv_any 
	ds `yvarlist'
	foreach yvar in `r(varlist)' {
		replace `yvar' = 0 if mi(`yvar') & !mi(acasi_ipv_treat)
	}
	
	tempfile replicationData_uncond
	save `replicationData_uncond', replace


/*******************************************************************************
 Table E1: Effect of Self-interviewing (SI) on Placebo Questions, unconditional on don't know/refusal responses
 - Table 3, imputing zeroes for don't know/refusals
*******************************************************************************/
local texname tableE1
local yvarlist acasi_placebo_q3 acasi_placebo_q6 acasi_placebo_q9 acasi_placebo_q11 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \begin{tabular}{c} Farm work \\ (past year) \end{tabular} &\begin{tabular}{c}  Market visit \\ (past week) \end{tabular}  & \begin{tabular}{c} Maize/Rice \\ (next week) \end{tabular} & \begin{tabular}{c} Meat \\ (next week) \end{tabular} \\"
	
// Panel A. Malawi
local panel_text "Panel A. Malawi"

use `replicationData_uncond', clear
keep if survey=="gd_mw_endline"
cap drop acasi_screening_pass
rename acasi_screening_pass3 acasi_screening_pass

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use `replicationData_uncond', clear
keep if survey=="gd_lrw2_endline"
cap drop acasi_screening_pass
rename acasi_screening_pass3 acasi_screening_pass

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\");
#d cr

// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")										
*******************************************************************************/	


/*******************************************************************************
 Table E2: Effect of Self-interviewing (SI) on IPV (Individual Questions, unconditional on don't know/refusal responses
  - Table 4, imputing zeroes for don't know/refusals
*******************************************************************************/
local texname tableE2
local numcol 5
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \multicolumn{4}{c}{\scriptsize =1 if responded yes to \emph{individual} question in the following category:} & \multirow{3}{*}{\begin{tabular}{c} All \\ questions \\ pooled \end{tabular} } \\ " ///
	"\cmidrule(lr){2-5}" ///
	" & \begin{tabular}{c} Controlling \\ Behavior \end{tabular} & \begin{tabular}{c} Emotional \\ IPV \end{tabular} & \begin{tabular}{c} Physical \\ IPV \end{tabular} & \begin{tabular}{c} Sexual \\ IPV \end{tabular} & \\" 

// Panel A. Malawi
local panel_text "Panel A. Malawi"

use `replicationData_uncond', clear
keep if survey=="gd_mw_endline"

est clear
running_regressions_qlevel, i(0) controls(${controls_rm})

#d;
exporting_results_qlevel, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use `replicationData_uncond', clear
keep if survey=="gd_lrw2_endline"

est clear
running_regressions_qlevel, i(0) controls(${controls_rm})

#d;
exporting_results_qlevel, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr
	
// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")		
*******************************************************************************/

/*******************************************************************************
 Table E3: Effect of Self-interviewing (SI) on IPV Indices, unconditional on don't know/refusal responses
 - Table 5, imputing zeroes for don't know/refusals
*******************************************************************************/
local texname tableE3
local yvarlist ctrl_bx ipv_emo ipv_phy ipv_sex ipv_any 
local numcol = wordcount("`yvarlist'")
local numcol_plus1 = `numcol'+1
local latex_header ///
	" & \multicolumn{4}{c}{\scriptsize  =1 if responded yes to \textit{at least one} question in the following category:} & \multirow{3}{*}{\begin{tabular}{c} Any \\ IPV  \end{tabular} } \\ " ///
	"\cmidrule(lr){2-5}" ///
	" & \begin{tabular}{c} Controlling \\ Behavior \end{tabular} & \begin{tabular}{c} Emotional \\ IPV \end{tabular} & \begin{tabular}{c} Physical \\ IPV \end{tabular} & \begin{tabular}{c} Sexual \\ IPV \end{tabular} & \\" 
			
// Panel A. Malawi
local panel_text "Panel A. Malawi"

use `replicationData_uncond', clear
keep if survey=="gd_mw_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results, texname(`texname') replace_append("replace") number("number") numcol(`numcol')
	prehead("\begin{tabular}{l *{`numcol'}{c}}" "\toprule") 
	posthead("`latex_header'" "\midrule" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr

// Panel B. Liberia Wave 2
local panel_text "Panel B. Liberia"

use `replicationData_uncond', clear
keep if survey=="gd_lrw2_endline"

est clear
running_regressions, yvarlist(`yvarlist') i(0) controls(${controls_rm})

#d;
exporting_results, texname(`texname') replace_append("append") number(" ") numcol(`numcol')
	prehead(" ") 
	posthead("\\" "\multicolumn{`numcol_plus1'}{l}{\textbf{`panel_text'}} \\")
	;
#d cr
	
// Ending line
estout * using "${raw_folder}/`texname'.tex", append style(tex) mlabel(none) collabel(none) drop(*) ///
	postfoot("\bottomrule" "\end{tabular}")		
*******************************************************************************/

exit

